﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Li.DingTalk.Model.Contacts
{
    /// <summary>
    /// 智能办公处理类
    /// </summary>
    public class attendanceHD
    {
        /// <summary>
        /// 考勤打卡记录开放
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="scs">考勤打卡记录结构体</param>
        /// <returns></returns>
        public static attendancecardrecord Attendancecardrecord(string access_token, attendancecardrecordstructural scs)
        {
            var path = string.Format("https://oapi.dingtalk.com/attendance/listRecord?access_token={0}", access_token);
            var StrJson = Newtonsoft.Json.JsonConvert.SerializeObject(scs);
            var selectlist = RequestHelper.Post(path, StrJson);
            return Newtonsoft.Json.JsonConvert.DeserializeObject<attendancecardrecord>(selectlist);
        }

        /// <summary>
        /// 签到
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="department_id">部门id（1 表示根部门）</param>
        /// <param name="start_time">开始时间，精确到毫秒</param>
        /// <param name="end_time">结束时间，精确到毫秒（默认为当前时间）</param>
        /// <param name="offset">支持分页查询，与size 参数同时设置时才生效，此参数代表偏移量，从0 开始</param>
        /// <param name="size">	支持分页查询，与offset 参数同时设置时才生效，此参数代表分页大小，最大100</param>
        /// <param name="order">排序，asc 为正序，desc 为倒序</param>
        /// <returns></returns>
        public static signlist Signlist(string access_token, string department_id, long start_time, long end_time, long offset, int size, string order)
        {
            var path = string.Format("https://oapi.dingtalk.com/checkin/record?access_token={0}&department_id={1}&start_time={2}&end_time={3}&offset={4}&size={5}&order={6}", access_token, department_id, start_time, end_time, offset, size, order);
            string resultJson = RequestHelper.Get(path);
            return Newtonsoft.Json.JsonConvert.DeserializeObject<signlist>(resultJson);
        }


        #region 智能办公信息
        /// <summary>
        /// 考勤打卡记录开放结构体
        /// </summary>
        public class attendancecardrecordstructural
        {
            /// <summary>
            /// 企业内的员工id列表，最多不能超过50个
            /// </summary>
            public string[] userIds
            {
                get;
                set;
            }

            /// <summary>
            /// 查询考勤打卡记录的起始工作日
            /// </summary>
            public string checkDateFrom
            {
                get;
                set;
            }

            /// <summary>
            /// 查询考勤打卡记录的结束工作日
            /// </summary>
            public string checkDateTo
            {
                get;
                set;
            }
        }

        /// <summary>
        /// 考勤打卡记录开放内容
        /// </summary>
        public class attendancecardrecord : ResultPackage
        {
            /// <summary>
            /// 考勤记录内容
            /// </summary>
            public attendancecardrecordlist[] recordresult
            {
                get;
                set;
            }
        }

        /// <summary>
        /// 考勤记录内容
        /// </summary>
        public class attendancecardrecordlist
        {
            /// <summary>
            /// 修改时间
            /// </summary>
            public long gmtModified
            {
                get;
                set;
            }

            /// <summary>
            /// 计算迟到和早退，基准时间
            /// </summary>
            public long baseCheckTime
            {
                get;
                set;
            }

            /// <summary>
            /// 考勤组ID
            /// </summary>
            public long groupId
            {
                get;
                set;
            }

            /// <summary>
            /// 时间结果（Normal:正常;Early:早退; Late:迟到;SeriousLate:严重迟到；NotSigned:未打卡）
            /// </summary>
            public string timeResult
            {
                get;
                set;
            }

            /// <summary>
            /// 设备id
            /// </summary>
            public string deviceId
            {
                get;
                set;
            }

            /// <summary>
            /// 用户打卡定位精度
            /// </summary>
            public float userAccuracy
            {
                get;
                set;
            }

            /// <summary>
            /// 工作日
            /// </summary>
            public long workDate
            {
                get;
                set;
            }

            /// <summary>
            /// 唯一标示ID
            /// </summary>
            public long id
            {
                get;
                set;
            }

            /// <summary>
            /// 考勤类型（OnDuty：上班，OffDuty：下班）
            /// </summary>
            public string checkType
            {
                get;
                set;
            }

            /// <summary>
            /// 排班打卡时间
            /// </summary>
            public long planCheckTime
            {
                get;
                set;
            }

            /// <summary>
            /// 企业应用的corpId
            /// </summary>
            public string corpId
            {
                get;
                set;
            }

            /// <summary>
            /// 位置结果（Normal:范围内；Outside:范围外）
            /// </summary>
            public string locationResult
            {
                get;
                set;
            }

            /// <summary>
            /// 用户打卡经度
            /// </summary>
            public double userLongitude
            {
                get;
                set;
            }

            /// <summary>
            /// 是否合法
            /// </summary>
            public string isLegal
            {
                get;
                set;
            }

            /// <summary>
            /// 创建时间
            /// </summary>
            public long gmtCreate
            {
                get;
                set;
            }

            /// <summary>
            /// 用户ID
            /// </summary>
            public string userId
            {
                get;
                set;
            }

            /// <summary>
            /// 用户打卡地址
            /// </summary>
            public string userAddress
            {
                get;
                set;
            }

            /// <summary>
            /// 用户打卡纬度
            /// </summary>
            public double userLatitude
            {
                get;
                set;
            }

            /// <summary>
            /// 数据来源 （ATM:考勤机;BEACON:IBeacon;DING_ATM:钉钉考勤机;APP_USER:用户打卡;APP_BOSS:老板改签;APP_APPROVE:审批系统;SYSTEM:考勤系统;APP_AUTO_CHECK:自动打卡）
            /// </summary>
            public string sourceType
            {
                get;
                set;
            }

            /// <summary>
            /// 实际打卡时间
            /// </summary>
            public long userCheckTime
            {
                get;
                set;
            }

            /// <summary>
            /// 定位方法
            /// </summary>
            public string locationMethod
            {
                get;
                set;
            }
        }

        /// <summary>
        /// 签到内容
        /// </summary>
        public class signlist : ResultPackage
        {
            /// <summary>
            /// 签到数据
            /// </summary>
            public signdata[] data
            {
                get;
                set;
            }
        }

        /// <summary>
        /// 签到数据
        /// </summary>
        public class signdata
        {
            /// <summary>
            /// 成员名称
            /// </summary>
            public string name
            {
                get;
                set;
            }

            /// <summary>
            /// 员工唯一标识ID（不可修改）
            /// </summary>
            public string userId
            {
                get;
                set;
            }

            /// <summary>
            /// 签到时间
            /// </summary>
            public long timestamp
            {
                get;
                set;
            }

            /// <summary>
            /// 头像url
            /// </summary>
            public string avatar
            {
                get;
                set;
            }

            /// <summary>
            /// 签到地址
            /// </summary>
            public string place
            {
                get;
                set;
            }

            /// <summary>
            /// 签到详细地址
            /// </summary>
            public string detailPlace
            {
                get;
                set;
            }

            /// <summary>
            /// 签到备注
            /// </summary>
            public string remark
            {
                get;
                set;
            }

            /// <summary>
            /// 签到照片url列表
            /// </summary>
            public string[] imageList
            {
                get;
                set;
            }
        }

        #endregion
    }
}
